package guggaTests.collections.dictionary
{
	import flexunit.framework.TestCase;
	import gugga.collections.dictionary.Dictionary;

	public class DictionaryTest extends TestCase
	{
		private var mDictionary : Dictionary;
		
		public function DictionaryTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public override function setUp() : void
		{
			mDictionary = new Dictionary();
		}
		
		public function testConstructor() : void
		{
			assertNotNull("Dictionary should not be null", mDictionary);
			assertEquals("Dictionary should be empty", 0, mDictionary.count);
			
		}
		
		public function testAddRemoveContainsValueContainsKey() : void
		{
			var key1 : Object = new Object();
			var key2 : Object = new Object();
			
			var value1 : Object = new Object();
			var value2 : Object = new Object();
			
			mDictionary.add(key1, value1);
			mDictionary.add(key2, value2);
			
			assertEquals("Dictionary should contain 2 elements", 2, mDictionary.count);
			assertEquals("Objects should be equal", value1, mDictionary[key1]);
			assertEquals("Objects should be equal", value2, mDictionary[key2]);
			assertTrue("Dictionary should contains value1", mDictionary.containsValue(value1));
			assertTrue("Dictionary should contains value2", mDictionary.containsValue(value2));
			assertTrue("Dictionary should contains key1", mDictionary.containsKey(key1));
			assertTrue("Dictionary should contains key2", mDictionary.containsKey(key2));
						
			mDictionary.remove(key1);
			
			assertEquals("Dictionary should contain 1 elements", 1, mDictionary.count);
			assertEquals("Objects should be equal", value2, mDictionary[key2]);
			assertFalse("Dictionary should not contain value1", mDictionary.containsValue(value1));
			assertTrue("Dictionary should contains value2", mDictionary.containsValue(value2));
			assertFalse("Dictionary should not contain key1", mDictionary.containsKey(key1));
			assertTrue("Dictionary should contains key2", mDictionary.containsKey(key2));
			
			mDictionary.remove(key2);
			
			assertEquals("Dictionary should contain 0 elements", 0, mDictionary.count);
			assertFalse("Dictionary should not contain value1", mDictionary.containsValue(value1));
			assertFalse("Dictionary should not contain value2", mDictionary.containsValue(value2));
			assertFalse("Dictionary should not contain key1", mDictionary.containsKey(key1));
			assertFalse("Dictionary should not contain key2", mDictionary.containsKey(key2));
		}
		
		public function testGetKeyByValue() : void
		{
			var key1 : Object = new Object();
			var key2 : Object = new Object();
			
			var value1 : Object = new Object();
			var value2 : Object = new Object();
			
			mDictionary.add(key1, value1);
			mDictionary.add(key2, value2);
			
			assertEquals("Keys should be equal", key1, mDictionary.getKeyByValue(value1));
			assertEquals("Keys should be equal", key2, mDictionary.getKeyByValue(value2));
		}
	}
}